package GUILayer;

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------------------
 * MinMaxCategoryPlotDemo.java
 * ---------------------------
 * (C) Copyright 2002-2004, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: MinMaxCategoryPlotDemo.java,v 1.12 2004/04/30 08:10:43 mungady Exp $
 *
 * Changes
 * -------
 * 08-Aug-2002 : Demo for a renderer contributed by Tomer Peretz (DG);
 * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
 *
 */

import java.awt.Color;
import java.awt.Dimension;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.MinMaxCategoryRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import java.awt.FlowLayout;
import java.util.ArrayList;

import javax.swing.JFrame;
/**
 * A simple demonstration application showing how to create a min/max category plot.
 *
 */
public class TemperatureSchema extends ApplicationFrame {
    /**
     * Creates a new demo.
     *
     * @param title  the frame title.
     */
	final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
	final int limit = 7;
	 int current = 0;
    public TemperatureSchema(final String title, ArrayList<String> info) {
        super(title);
        setPreferedSize(800,500);
        setSize(800,500);
        this.setMinimumSize(new Dimension(800,500));
        this.setMaximumSize(new Dimension(800,500));
        setResizable(false);
        // create a dataset...
        pack();
        
        setVisible(true);
       if(title.equals("Temperature"))
        for(String value: info)
      {
    	  
      String[] temp = value.split("\\+");
        dataset.addValue(Double.parseDouble(temp[0]), "First", temp[1]);
        dataset.addValue(Double.parseDouble(temp[0]), "Second", temp[1]);
        System.out.println("coco is typing here:"+temp[0]);
       
      }
       
       if(title.equals("Puls"))
           for(String value: info)
         {
       	  
         String[] temp = value.split("\\+");
           dataset.addValue(Integer.parseInt(temp[0]), "First", temp[1]);
           dataset.addValue(Integer.parseInt(temp[0]), "Second", temp[1]);
          
         }
       
       if(title.equals("Blood Pressure"))
           for(String value: info)
         {
       	  
         String[] temp = value.split("\\+");
           dataset.addValue(Integer.parseInt(temp[0]), "First", temp[2]);
           dataset.addValue(Integer.parseInt(temp[1]), "Second", temp[2]);
          
         }
       
       if(title.equals("Respiration"))
           for(String value: info)
         {
       	  
         String[] temp = value.split("\\+");
           dataset.addValue(Integer.parseInt(temp[0]), "First", temp[1]);
           dataset.addValue(Integer.parseInt(temp[0]), "Second", temp[1]);
          
         }
       
       
       
       
       
       
       
       
       
        // create the chart...
        final JFreeChart chart = ChartFactory.createBarChart(
            "",  // chart title
            "Date",               // domain axis label
            "Value",                  // range axis label
            dataset,                  // data
            PlotOrientation.VERTICAL,
            false,                     // include legend
            false,                     // tooltips
            false                     // urls
        );
        // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
        // set the background color for the chart...
        chart.setBackgroundPaint(Color.yellow);
        // get a reference to the plot for further customisation...
        final CategoryPlot plot = chart.getCategoryPlot();
        plot.setRenderer(new MinMaxCategoryRenderer());
        // OPTIONAL CUSTOMISATION COMPLETED.
        // add the chart to a panel...
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setDismissDelay(4000);
        chartPanel.setRangeZoomable(false);
        chartPanel.setEnforceFileExtensions(false);
        FlowLayout flowLayout = (FlowLayout) chartPanel.getLayout();
        chartPanel.setMouseZoomable(false);
        chartPanel.setRefreshBuffer(true);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 400));
        setContentPane(chartPanel);
    }
    private void setPreferedSize(int i, int j) {
		// TODO Auto-generated method stub
		
	}
	public void addValues(double value, String date)
    {
    	if(current <= limit){
    	dataset.addValue(value, "First", date);
    	dataset.addValue(value, "Second", date); 
    	current++;
    	}
    }
    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.ru/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************
 
   /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(final String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("37.5+2012-05-03 21:03:04");
    	final TemperatureSchema demo = new TemperatureSchema(
            "Temperature Schema",list
        );
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }
}